home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-09-06 | 2.0 KB | 87 lines | [TEXT/MACA] |
- /*
- * dlog.c - handle dialogs for the game of Tablut
- *
- */
-
- #include <memory.h>
- #include <quickdraw.h>
- #include <window.h>
- #include <event.h>
- #include <textedit.h>
- #include <dialog.h>
- #include <control.h>
- #include <toolutil.h>
- #define watchCursor 4 /* Should be in TOOLUTIL.H but isn't. */
- #include <resource.h>
-
- /*
- * saydialog() - show the user the given dialog.
- */
- saydialog(dlgid)
- short dlgid; /* Resource ID of the dialog to show */
- {
- short itemhit;
- DialogPtr reportptr;
-
- /*
- * Get the dialog; NIL => use heap storage; -1 => make dlg frontmost.
- * Wait for some item to be selected (OK is the only one),
- * then free up the memory and erase the dialog.
- */
- reportptr = GetNewDialog(dlgid, (char *) 0, (long) -1);
- ModalDialog((ProcPtr) 0, &itemhit);
- DisposDialog(reportptr);
- }
-
- /*
- * radioswitch() - turn one radio button off & another one on,
- * returning the item ID of the new "on" button.
- */
- int
- radioswitch(ptr, oncontrl, offcontrl)
- DialogPtr ptr;
- int oncontrl, offcontrl; /* items to turn on and off, respectively */
- {
- int itemtype;
- ControlHandle item;
- Rect itembox;
-
- GetDItem(ptr, offcontrl, &itemtype, &item, &itembox);
- SetCtlVal(item, 0);
- GetDItem(ptr, oncontrl, &itemtype, &item, &itembox);
- SetCtlVal(item, 1);
- return(oncontrl);
- }
-
- /*
- * justdigs() - restrict the contents of an EditText item to just the given
- * number of digits. I.E., throw out non-digit characters & characters
- * beyond the end of the field.
- * The field must be less than 100 characters wide.
- */
-
- justdigs(ptr, field, width)
- DialogPtr ptr;
- int field; /* # of the dialog item to modify */
- int width; /* max # of digits in the field */
- {
- int itemtype;
- ControlHandle item;
- Rect itembox;
- static char buf[100];
- char *src, *dst; /* pointers for removing non-digits */
-
- GetDItem(ptr, field, &itemtype, &item, &itembox);
- GetIText(item, buf);
- ptoc(buf);
-
- dst = &buf[0];
- for (src = &buf[0]; (*dst = *src); ++src) {
- if (*dst >= 0 && *dst <= '9') ++dst;
- }
- buf[width] = '\0';
-
- ctop(buf);
- SetIText(item, buf);
- }
-